cmake_minimum_required(VERSION 3.16)

project(MyProject LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)

# 创建一个可执行程序
add_executable(MyProject
  main.cpp
  myhead.h
)

# 链接 Qt 的 Core 组件
target_link_libraries(MyProject Qt${QT_VERSION_MAJOR}::Core)

# 设置自定义安装前缀
set(CMAKE_INSTALL_PREFIX "D:/Mydata")

# 包含 GNUInstallDirs 模块以使用标准的安装目录变量
include(GNUInstallDirs)

# 输出安装目录信息，使其更加清晰
message(STATUS "Library installation directory: ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
message(STATUS "Executable installation directory: ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")


# 安装可执行程序
install(TARGETS MyProject
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)


# 假设你有一些头文件在 include 目录下，安装它们
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include)
    install(DIRECTORY include/
        DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}
        FILES_MATCHING PATTERN "*.h"
    )
    message(STATUS "Header files installation directory: ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
else()
    message(WARNING "No include directory found, skipping header file installation.")
endif()


# 假设你有一些库文件在 lib 目录下，安装它们
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/lib)
    install(DIRECTORY lib/
        DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
        FILES_MATCHING PATTERN "*.a" PATTERN "*.so" PATTERN "*.dll"
    )
    message(STATUS "Library files installation directory: ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
else()
    message(WARNING "No lib directory found, skipping library file installation.")
endif()


# 假设你有一些源文件在 src 目录下，安装它们
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src)
    install(DIRECTORY src/
        DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SRCDIR}
        FILES_MATCHING PATTERN "*.cpp" PATTERN "*.c"
    )
    message(STATUS "Source files installation directory: ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SRCDIR}")
else()
    message(WARNING "No src directory found, skipping source file installation.")
endif()
